package com.newtouch.bxzs.policy.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.policy.config.MyLog;
import com.newtouch.bxzs.policy.model.bo.PreservationBO;
import com.newtouch.bxzs.policy.model.bo.enterprise.*;
import com.newtouch.bxzs.policy.model.bo.family.PolicyUserListBO;
import com.newtouch.bxzs.policy.model.vo.PolicyInfoPageVO;
import com.newtouch.bxzs.policy.model.vo.PolicyUserListVO;
import com.newtouch.bxzs.policy.model.vo.PreservationProgressInfoVO;
import com.newtouch.bxzs.policy.model.vo.enterprise.*;
import com.newtouch.bxzs.policy.service.EnterprisePolicyService;
import com.newtouch.bxzs.policy.util.PolicyListPageUtils;
import com.newtouch.bxzs.policy.util.QueryCriteriaUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 企业单管理controller层
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 10:12</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "企业单管理")
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/enterprisePolicy")
public class EnterprisePolicyController {
    /** 静态变量：系统日志 */
    private static final Log logger = LogFactory.getLog(EnterprisePolicyController.class);

    @Resource
    private EnterprisePolicyService enterprisepolicyService;

    @ApiOperation(value = "查询企业单列表")
    @PostMapping("/getEnterprisePolicyPolicyList")
    @MyLog(systemFunctionName = "企业单管理",systemFunctionUrl = "/enterprisePolicy/getEnterprisePolicyPolicyList",userOperationType = 4,userOperationSummary = "查询企业单列表")
    public BaseResponse<EnterprisePolicyBO> enterprisePolicyList(@RequestBody EnterprisePolicyVO enterprisePolicyVO) {
        logger.info("查询企业单列表");
       return RespGenerator.returnOK(enterprisepolicyService.getEnterprisePolicyList(enterprisePolicyVO));
//       return RespGenerator.returnOK(policyExternal.getIndividualPolicyList());
    }

    @ApiOperation(value = "根据保单号调用外部接口查询企业单详情")
    @PostMapping("/getEnterprisePolicyInfo")
    @MyLog(systemFunctionName = "企业单管理",systemFunctionUrl = "/enterprisePolicy/getEnterprisePolicyInfo",userOperationType = 4,userOperationSummary = "查询企业单详情")
    public BaseResponse<EnterprisePolicyBO> enterprisePolicyInfo(@RequestBody EnterprisePolicyInfoVO enterprisePolicyInfoVO) {
        logger.info("查询企业单详情");
        return RespGenerator.returnOK(enterprisepolicyService.getEnterprisePolicyInfo(enterprisePolicyInfoVO));
    }

    @ApiOperation(value = "根据保单号调用外部接口查询企业单保全信息")
    @PostMapping(value = "/getEnterprisePolicyPreservation")
    @MyLog(systemFunctionName = "企业单管理",systemFunctionUrl = "/enterprisePolicy/getEnterprisePolicyPreservation",userOperationType = 4,userOperationSummary = "查询企业单保全信息")
    public BaseResponse<PreservationBO> enterprisePolicyPreservation(@RequestBody PolicyInfoPageVO policyInfoPageVO) {
        logger.info("调用查询企业单保全信息外部接口");
        List<PreservationBO> enterprisePreservationListBO = enterprisepolicyService.getEnterprisePolicyPreservation(policyInfoPageVO);
        if(!CollectionUtil.isEmpty(enterprisePreservationListBO)){
            //对获取的保全信息进行分页处理
            PolicyListPageUtils<PreservationBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(enterprisePreservationListBO,policyInfoPageVO.getPageSize(),policyInfoPageVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(enterprisePreservationListBO);
    }

    @ApiOperation(value = "根据保单号调用外部接口查询企业单理赔信息")
    @PostMapping(value = "/getEnterprisePolicyClaims")
    @MyLog(systemFunctionName = "企业单管理",systemFunctionUrl = "/enterprisePolicy/getEnterprisePolicyClaims",userOperationType = 4,userOperationSummary = "查询企业单理赔信息")
    public BaseResponse<EnterpriseClaimsBO> enterprisePolicyClaims(@RequestBody PolicyInfoPageVO policyInfoPageVO) {
        logger.info("调用查询企业单理赔信息外部接口");
        List<EnterpriseClaimsBO> claimsListBO = enterprisepolicyService.getEnterprisePolicyClaims(policyInfoPageVO);
        if(!CollectionUtil.isEmpty(claimsListBO)){
            //对获取的理赔信息进行分页处理
            PolicyListPageUtils<EnterpriseClaimsBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(claimsListBO,policyInfoPageVO.getPageSize(),policyInfoPageVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(claimsListBO);
    }

    @ApiOperation(value = "根据保单号调用外部接口查询企业单人员清单信息")
    @PostMapping(value = "/getEnterprisePolicyUserList")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getEnterprisePolicyUserList",userOperationType = 4,userOperationSummary = "查询企业单人员清单列表")
    public BaseResponse<PolicyUserListBO> enterprisePolicyUserList(@RequestBody PolicyUserListVO policyUserListVO) {
        logger.info("查询企业单人员清单接口");
        List<PolicyUserListBO> policyUserListBO = enterprisepolicyService.getEnterprisePolicyUserList(policyUserListVO);
        //对人员清单列表进行分页处理
        if(!CollectionUtil.isEmpty(policyUserListBO)){
            PolicyListPageUtils<PolicyUserListBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(policyUserListBO,policyUserListVO.getPageSize(),policyUserListVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(policyUserListBO);
    }

    @ApiOperation(value = "查询企业单保全进度列表")
    @PostMapping(value = "/getPreservationListByEnterPrisePolicy")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getPreservationListByEnterPrisePolicy",userOperationType = 4,userOperationSummary = "查询企业单保全进度列表")
    public BaseResponse<EnterprisePreservationProgressInfoBO> preservationListByEnterPrisePolicy(@RequestBody EnterprisePreservationVO enterprisePreservationVO) {
        logger.info("查询企业单保全进度列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(enterprisePreservationVO.getApplicationStartDate(),enterprisePreservationVO.getApplicationDeadline());
        List<EnterprisePreservationProgressInfoBO> enterprisePreservationProgressListBO = enterprisepolicyService.getPreservationListByEnterPrisePolicy(enterprisePreservationVO);
        if(!CollectionUtil.isEmpty(enterprisePreservationProgressListBO)){
            //对获取的保全进度列表信息进行分页处理
            PolicyListPageUtils<EnterprisePreservationProgressInfoBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(enterprisePreservationProgressListBO,enterprisePreservationVO.getPageSize(),enterprisePreservationVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(enterprisePreservationProgressListBO);
    }

    @ApiOperation(value = "查看企业单保全进度详情")
    @PostMapping(value = "/getPreservationInfoByEnterPrisePolicy")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getPreservationInfoByEnterPrisePolicy",userOperationType = 4,userOperationSummary = "查看企业单保全进度详情")
    public BaseResponse<EnterprisePreservationProgressInfoBO> preservationInfoByEnterPrisePolicy(@RequestBody PreservationProgressInfoVO preservationProgressInfoVO) {
        logger.info("查看企业单保全进度详情");
        return RespGenerator.returnOK(enterprisepolicyService.getPreservationInfoByEnterPrisePolicy(preservationProgressInfoVO));
    }

    @ApiOperation(value = "查询企业单理赔进度列表")
    @PostMapping(value = "/getClaimsProgressListByEnterprisePolicy")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getClaimsProgressListByEnterprisePolicy",userOperationType = 4,userOperationSummary = "查询企业单理赔进度列表")
    public BaseResponse<EnterpriseClaimsProgressBO> claimsProgressListByEnterprisePolicy(@RequestBody EnterpriseClaimsVO enterpriseClaimsVO) {
        logger.info("查询个单理赔进度列表");
        List<EnterpriseClaimsProgressBO> enterpriseClaimsProgressListBO = enterprisepolicyService.getClaimsProgressListByEnterprisePolicy(enterpriseClaimsVO);
        if(!CollectionUtil.isEmpty(enterpriseClaimsProgressListBO)){
            //对获取的理赔进度信息进行分页处理
            PolicyListPageUtils<EnterpriseClaimsProgressBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(enterpriseClaimsProgressListBO,enterpriseClaimsVO.getPageSize(),enterpriseClaimsVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(enterpriseClaimsProgressListBO);
    }

    @ApiOperation(value = "查询企业单理赔进度--个人")
    @PostMapping(value = "/getClaimsProgressUserListByEnterprisePolicy")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getClaimsProgressUserListByEnterprisePolicy",userOperationType = 4,userOperationSummary = "查询企业单理赔进度列表--个人")
    public BaseResponse<EnterpriseClaimsProgressBO> claimsProgressUserListByEnterprisePolicy(@RequestBody PolicyUserListVO policyUserListVO) {
        logger.info("查询个单理赔进度列表");
        List<EnterpriseClaimsProgressBO> claimsProgressListBO = enterprisepolicyService.getClaimsProgressUserListByEnterprisePolicy(policyUserListVO);
        if(!CollectionUtil.isEmpty(claimsProgressListBO)){
            //对获取的理赔进度信息进行分页处理
            PolicyListPageUtils<EnterpriseClaimsProgressBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(claimsProgressListBO,policyUserListVO.getPageSize(),policyUserListVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(claimsProgressListBO);
    }

    @ApiOperation(value = "查询企业单理赔进度--批次")
    @PostMapping(value = "/getClaimsProgressBatchListByEnterprisePolicy")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getClaimsProgressBatchListByEnterprisePolicy",userOperationType = 4,userOperationSummary = "查询企业单理赔进度列表---批次")
    public BaseResponse<EnterpriseClaimsProgressBO> claimsProgressBatchListByEnterprisePolicy(@RequestBody PolicyInfoPageVO policyInfoPageVO) {
        logger.info("查询个单理赔进度列表");
        List<EnterpriseClaimsProgressBO> claimsProgressListBO = enterprisepolicyService.getClaimsProgressBatchListByEnterprisePolicy(policyInfoPageVO);
        if(!CollectionUtil.isEmpty(claimsProgressListBO)){
            //对获取的理赔进度信息进行分页处理
            PolicyListPageUtils<EnterpriseClaimsProgressBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(claimsProgressListBO,policyInfoPageVO.getPageSize(),policyInfoPageVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(claimsProgressListBO);
    }

    @ApiOperation(value = "查看企业单新契约详情")
    @PostMapping(value = "/getNewContractInfoByEnterprisePolicy")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getNewContractInfoByEnterprisePolicy",userOperationType = 4,userOperationSummary = "查看企业单新契约详情")
    public BaseResponse<EnterprisePolicyNewContractBO> newContractInfoByEnterprisePolicy(@RequestBody EnterprisePolicyNewContractInfoVO enterprisePolicyNewContractInfoVO) {
        logger.info("查看企业单新契约详情");
        return RespGenerator.returnOK(enterprisepolicyService.getNewContractInfoByEnterprisePolicy(enterprisePolicyNewContractInfoVO));
    }

    @ApiOperation(value = "查询企业单新契约列表")
    @PostMapping(value = "/getNewContractListByEnterprisePolicy")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getNewContractListByEnterprisePolicy",userOperationType = 4,userOperationSummary = "查询企业单新契约列表")
    public BaseResponse<EnterprisePolicyNewContractBO> newContractListByEnterprisePolicy(@RequestBody EnterprisePolicyNewContractVO enterprisePolicyNewContractVO) {
        logger.info("查询企业单新契约列表");
        List<EnterprisePolicyNewContractBO> policyNewContractListBO = enterprisepolicyService.getNewContractListByEnterprisePolicy(enterprisePolicyNewContractVO);
        if(!CollectionUtil.isEmpty(policyNewContractListBO)){
            //对获取的新契约保单信息进行分页处理
            PolicyListPageUtils<EnterprisePolicyNewContractBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(policyNewContractListBO,enterprisePolicyNewContractVO.getPageSize(),enterprisePolicyNewContractVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(policyNewContractListBO);
    }

    @ApiOperation(value = "根据保单号调用外部接口查询企业单新契约人员清单信息")
    @PostMapping(value = "/getNewContractIUserListByEnterprisePolicy")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getNewContractIUserListByEnterprisePolicy",userOperationType = 4,userOperationSummary = "查询企业单人员清单列表")
    public BaseResponse<PolicyUserListBO> newContractIUserListByEnterprisePolicy(@RequestBody EnterprisePolicyNewContractUserListVO enterprisePolicyNewContractUserListVO) {
        logger.info("查询企业单人员清单接口");
        List<PolicyUserListBO> policyUserListBO = enterprisepolicyService.getNewContractUserListByEnterprisePolicy(enterprisePolicyNewContractUserListVO);
        //对人员清单列表进行分页处理
        if(!CollectionUtil.isEmpty(policyUserListBO)){
            PolicyListPageUtils<PolicyUserListBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(policyUserListBO,enterprisePolicyNewContractUserListVO.getPageSize(),enterprisePolicyNewContractUserListVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(policyUserListBO);
    }

    @ApiOperation(value = "查询企业单满期列表")
    @PostMapping(value = "/getExpirationPolicyListByEnterprisePolicy")
    @MyLog(systemFunctionName = "企业单管理",systemFunctionUrl = "/enterprisePolicy/getExpirationPolicyListByEnterprisePolicy",userOperationType = 4,userOperationSummary = "查询企业单满期列表")
    public BaseResponse<EnterpriseExpirationPolicyBO> expirationPolicyListByEnterprisePolicy(@RequestBody EnterpriseExpirationPolicyVO enterpriseExpirationPolicyVO) {
        logger.info("查询企业单满期信息列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(enterpriseExpirationPolicyVO.getExpirationStartDate(),enterpriseExpirationPolicyVO.getExpirationDeadline());
        List<EnterpriseExpirationPolicyBO> expirationPolicyBO = enterprisepolicyService.getExpirationPolicyListByEnterprisePolicy(enterpriseExpirationPolicyVO);
        if(!CollectionUtil.isEmpty(expirationPolicyBO)){
            //对获取的满期数据进行分页处理
            PolicyListPageUtils<EnterpriseExpirationPolicyBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(expirationPolicyBO,enterpriseExpirationPolicyVO.getPageSize(),enterpriseExpirationPolicyVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(expirationPolicyBO);
    }

    @ApiOperation(value = "查询企业单续期列表")
    @PostMapping(value = "/getRenewalPolicyListByEnterPrisePolicy")
    @MyLog(systemFunctionName = "企业单管理",systemFunctionUrl = "/enterprisePolicy/getRenewalPolicyListByEnterPrisePolicy",userOperationType = 4,userOperationSummary = "查询企业单续期列表")
    public BaseResponse<EnterpriseRenewalPolicyBO> renewalPolicyListByEnterPrisePolicy(@RequestBody EnterpriseRenewalPolicyVO enterpriseRenewalPolicyVO) {
        logger.info("查询企业单续期信息列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(enterpriseRenewalPolicyVO.getPaymentStartDate(),enterpriseRenewalPolicyVO.getPaymentDeadline());
        List<EnterpriseRenewalPolicyBO> renewalPolicyListBO = enterprisepolicyService.getRenewalPolicyListByEnterPrisePolicy(enterpriseRenewalPolicyVO);
        if(!CollectionUtil.isEmpty(renewalPolicyListBO)){
            PolicyListPageUtils<EnterpriseRenewalPolicyBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(renewalPolicyListBO,enterpriseRenewalPolicyVO.getPageSize(),enterpriseRenewalPolicyVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(renewalPolicyListBO);
    }

    @ApiOperation(value = "通知跳转企业单保全进度列表")
    @PostMapping(value = "/getPreservationListByEnterPrisePolicyNotice")
    @MyLog(systemFunctionName = "企业单保单管理",systemFunctionUrl = "/enterprisePolicy/getPreservationListByEnterPrisePolicyNotice",userOperationType = 4,userOperationSummary = "通知跳转企业单保全进度列表")
    public BaseResponse<EnterprisePreservationProgressInfoBO> preservationListByEnterPrisePolicyNotice(@RequestBody EnterprisePreservationVO enterprisePreservationVO) {
        logger.info("通知跳转企业单保全进度列表");
        return RespGenerator.returnOK(enterprisepolicyService.getPreservationListByEnterPrisePolicy(enterprisePreservationVO));
    }

    @ApiOperation(value = "通知跳转企业单满期列表")
    @PostMapping(value = "/getExpirationPolicyListByEnterprisePolicyNotice")
    @MyLog(systemFunctionName = "企业单管理",systemFunctionUrl = "/enterprisePolicy/getExpirationPolicyListByEnterprisePolicyNotice",userOperationType = 4,userOperationSummary = "通知跳转企业单满期列表")
    public BaseResponse<EnterpriseExpirationPolicyBO> expirationPolicyListByEnterprisePolicyNotice(@RequestBody EnterpriseExpirationPolicyVO enterpriseExpirationPolicyVO) {
        logger.info("通知跳转企业单满期列表");
        return RespGenerator.returnOK(enterprisepolicyService.getExpirationPolicyListByEnterprisePolicy(enterpriseExpirationPolicyVO));
    }

    @ApiOperation(value = "通知跳转企业单续期列表")
    @PostMapping(value = "/getRenewalPolicyListByEnterPrisePolicyNotice")
    @MyLog(systemFunctionName = "企业单管理",systemFunctionUrl = "/enterprisePolicy/getRenewalPolicyListByEnterPrisePolicyNotice",userOperationType = 4,userOperationSummary = "通知跳转企业单续期列表")
    public BaseResponse<EnterpriseRenewalPolicyBO> renewalPolicyListByEnterPrisePolicyNotice(@RequestBody EnterpriseRenewalPolicyVO enterpriseRenewalPolicyVO) {
        logger.info("通知跳转企业单续期列表");
        return RespGenerator.returnOK(enterprisepolicyService.getRenewalPolicyListByEnterPrisePolicy(enterpriseRenewalPolicyVO));
    }
}
